const svgCaptcha = require("svg-captcha");
const CaptchaService = {
	gen(req,res,next){
		var captcha = svgCaptcha.create({
			color:true,
			noise:4
		});
		req.session.captcha = captcha.text;
		res.json({
			res_code:1,
			res_error:"",
			res_body:{
				data:captcha.data
			}
		});
	},
	verify(req,res,next){
		const {code} = res.query;
		if(code.toUpperCase()===req.session.captcha.toUpperCase()){
			res.json({
				res_code:1,
				res_error:"",
				res_body:{
					valid:true
				}
			});
		}else{
			res.json({
				res_code:1,
				res_error:"",
				res_body:{
					valid:false
				}
			});
		}
	}
};
module.exports = CaptchaService;